/*
 * GridBrokerLocalJPanel.java
 *
 * Created on Utorok, 2007, november 6, 14:03
 */

package gui;

import logic.gridNodes.GridBroker;

/**
 *
 * @author  handsome
 */
public class GridBrokerLocalJPanel extends ParametersPanel {
    
    GridBroker BrokerLocal = null;
    /** Creates new form GridBrokerLocalJPanel */
    public GridBrokerLocalJPanel() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        NameJLabel = new javax.swing.JLabel();
        NameJTxtField = new javax.swing.JTextField();

        NameJLabel.setText("Name :");

        NameJTxtField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NameJTxtFieldActionPerformed(evt);
            }
        });
        NameJTxtField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                NameJTxtFieldFocusLost(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(NameJLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(NameJTxtField, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(73, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(NameJLabel)
                    .addComponent(NameJTxtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(345, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    
    /**
     * Nastavenie parametra - meno pre lokalneho brokera          
     */
    private void nameSet(){
        try {
            BrokerLocal.setName(NameJTxtField.getText());
        } catch (Exception ex) {
            NameJTxtField.setText(BrokerLocal.getName());
            GangstersGrid.showErrorMessage(ex.getMessage());
        }
    }
    
    
    private void NameJTxtFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_NameJTxtFieldFocusLost
        nameSet();
    }//GEN-LAST:event_NameJTxtFieldFocusLost

    private void NameJTxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NameJTxtFieldActionPerformed
        nameSet();
    }//GEN-LAST:event_NameJTxtFieldActionPerformed
    
    /**
     * Nastavi lokalnemu brokeru vsetky jeho potrebne parametre
     */
    public void FillUpBrokerLocalDetails(){
        nameSet();
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel NameJLabel;
    private javax.swing.JTextField NameJTxtField;
    // End of variables declaration//GEN-END:variables

    public void setObject(Object o) {
        BrokerLocal = ((GridBroker)o);
        NameJTxtField.setText(BrokerLocal.getName());
    }

    public void saveObjectValues() {
        if (BrokerLocal != null){
            FillUpBrokerLocalDetails();
        }
    }
    
}
